import unittest
from ChessBoard import *
from MoveStore import *

"""
Peter Kelly
11203901
Covers the initial behaviour of the method before
commencing refactoring. Note that the method will
return moves made after calling either addMove() 
or also in fact addTextMove().

Added tests for a second method in MoveStore - getLastMove()
Introduced after pulling in another groups work.
"""
class TestGetAllTextMoves(unittest.TestCase):

    def setUp(self):
        self.cb = ChessBoard()
        self.store = MoveStore(self.cb)

    def tearDown(self):
        self.cb.resetBoard()

    def testGetAllTextMoves_performOneMove(self):
	self.cb.addMove((0,6), (0,5))
        moves = self.store.getAllTextMoves()
        self.assertEqual(['a3'], moves)

    def testGetAllTextMoves_performMultipleMoves(self):
        self.cb.addMove((0,6),(0,5))
        self.cb.addMove((0,1),(0,2))
        self.cb.addMove((1,6),(1,4))
        moves = self.store.getAllTextMoves()
        self.assertEqual(['a3','a6','b4'], moves)

    def testGetAllTextMoves_performInvalidMove_IsNone(self):
        self.cb.addMove((3,3), (9,9))
        moves = self.store.getAllTextMoves()
        self.assertEqual(moves, None)

    def testGetAllTextMoves_performValidThenInvalid(self):
        self.cb.addMove((0,6),(0,5))
        self.cb.addMove((9,9),(20,20))
        moves = self.store.getAllTextMoves()
        self.assertEqual(['a3'], moves)

    def testGetAllTextMoves_addedSingleTextMove(self):
        self.cb.addTextMove('e4')
        moves = self.store.getAllTextMoves()
        self.assertEqual(['e4'], moves)

    def testGetAllTextMoves_addMultipleTextMoves(self):
        self.cb.addTextMove('e4')
        self.cb.addTextMove('c5')
        moves = self.store.getAllTextMoves()
        self.assertEqual(['e4','c5'], moves)

    def testGetLastMove_newGame_returnsNone(self):
        lastMove = self.store.getLastMove()
        self.assertEqual(lastMove, None)

    def testGetLastMove_movePerformed_returnsLastMove(self):
        self.cb.addMove((0,6),(0,5))
        self.cb.addMove((0,1),(0,2))
        lastMove = self.store.getLastMove()
        self.assertEqual(((0, 1), (0, 2)), lastMove)

    def testGetLastTextMove_newGame_returnsNone(self):
        lastMove = self.store.getLastTextMove()
        self.assertEqual(lastMove, None)

    def testGetLastTextMove_movePerformed_returnsLastMoveInFormat(self):
        self.cb.addTextMove('b4')
        self.cb.addTextMove('a6')
        lastMove = self.store.getLastTextMove()
        self.assertEqual(lastMove, 'a6')

def main():
    unittest.main()

if __name__ == '__main__':
    main()
